package com.drojian.demo2.cartoon;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.drojian.demo.R;

public class AttributeCartoonActivity extends AppCompatActivity implements View.OnClickListener {
    private ObjectAnimator animator1;
    private ObjectAnimator animator2;
    private ObjectAnimator animator3;
    private ObjectAnimator animator4;
    private ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.part2_activity_attribute_cartoon);
        bind();
        initAnimator();
    }
    public void bind(){
        Button btn_one = findViewById(R.id.btn_one);
        Button btn_two = findViewById(R.id.btn_two);
        Button btn_three = findViewById(R.id.btn_three);
        Button btn_four = findViewById(R.id.btn_four);
        Button btn_five = findViewById(R.id.btn_five);
        image = findViewById(R.id.img_cartoon);

        btn_one.setOnClickListener(this);
        btn_two.setOnClickListener(this);
        btn_three.setOnClickListener(this);
        btn_four.setOnClickListener(this);
        btn_five.setOnClickListener(this);
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_one :
                animator1.setDuration(3000);
                animator1.start();
                break;
            case R.id.btn_two :
                animator2.setDuration(3000);
                animator2.start();
                break;
            case R.id.btn_three :
                animator3.setDuration(3000);
                animator3.start();
                break;
            case R.id.btn_four :
                animator4.setDuration(3000);
                animator4.start();
                break;
            case R.id.btn_five :
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.play(animator4).after(animator3).after(animator2).after(animator1);
                //todo
                animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
                animatorSet.setDuration(3000);
                animatorSet.start();
                break;
        }
    }
    private void initAnimator() {
        float height = 0;
        animator1 = ObjectAnimator.ofFloat(image, "alpha", 1f, 0f, 1f, 0f, 1f);
        animator2 = ObjectAnimator.ofFloat(image, "rotation", 0f, 360f, 0f);
        animator3 = ObjectAnimator.ofFloat(image, "scaleX", 2f, 4f, 1f, 0.5f, 1f);
        animator4 = ObjectAnimator.ofFloat(image, "translationY", height / 8, -100,  height / 2);
    }




}